package com.gxa.list.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxa.common.R;
import com.gxa.common.entity.platform_maintenance_service1001.Question;
import com.gxa.list.mapper.QuestionListMapper;
import com.gxa.list.service.QuestionListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class QuestionListServiceImpl implements QuestionListService {


    @Autowired
    private QuestionListMapper questionListMapper;


    @Override
    public R addQuestionList(Question question) {

        R r = new R();
        int result = questionListMapper.insert(question);
        if(result > 0){
            r.setCode(200);
            r.setMessage("添加成功");
            r.setData(result);
        }else {
            r.setCode(500);
            r.setMessage("添加失败");
        }

        return r;
    }

    @Override
    public R updateQuestionList(Question question) {

        R r = new R();
        int result = questionListMapper.updateById(question);
        if(result > 0){
            r.setCode(200);
            r.setMessage("修改成功");
            r.setData(result);
        }else {
            r.setCode(500);
            r.setMessage("修改失败");
        }

        return r;

    }

    @Override
    public R selectQuestionListByPage(Integer currentPage, Integer pageSize) {
        R r = new R();
        QueryWrapper<Question> queryWrapper = new QueryWrapper<>();
        Page<Question> page = new Page<>(currentPage,pageSize);
        Page<Question> questionPage = questionListMapper.selectPage(page, queryWrapper);
        r.setMessage("按照分页查询成功");
        r.setCode(200);
        r.setData(questionPage);

        return r;
    }

    @Override
    public R delQuestionByIds(List<Integer> ids) {

        R r = new R();
        int result = questionListMapper.deleteBatchIds(ids);
        if(result > 0){
            r.setCode(200);
            r.setMessage("删除成功");
            r.setData(result);
        }else {
            r.setCode(500);
            r.setMessage("删除失败");
        }
        return r;
    }

    @Override
    public R selectQuestionByConditions(Question question) {
        List<Question> questionList = questionListMapper.selectQuestionByConditions(question);
        R r = new R();
        r.setCode(200);
        r.setMessage("按照条件查询成功");
        r.setData(questionList);
        return r;
    }

    @Override
    public R disableQuestion(Question question) {
        R r = new R();
        int result = questionListMapper.updateById(question);
        if(question.getStatus() == 1){
            r.setCode(200);
            r.setMessage("禁用成功");
            r.setData(result);
            r.setData(question.getStatus());
        }else{
            r.setMessage("已经是禁用状态");
        }

        return r;
    }

    @Override
    public R selectQuestionById(Question question) {
        R r = new R();
        Question question1 = questionListMapper.selectById(question.getId());
       r.setCode(200);
       r.setMessage("查询成功");
       r.setData(question1);
        return r;
    }

    @Override
    public R selectTwoTableQuestion(Question question) {

        Question selectByIdList = questionListMapper.selectById(question.getId());

        return null;
    }


}
